/*
 *  $Id: Absorb.cs 975 2009-12-16 17:13:22Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

namespace Ragima.Affects {
    /// <summary>
    /// Эффект: поглощение урона
    /// Параметр: тип урона
    /// Дает поглощение определенного типа урона, меняя его действие на обратное.
    /// </summary>
    public class Absorb: Affect {
        public static readonly Languages.Phrase AbsorbFull = new Languages.Phrase("affect.absorb.full");
        public static readonly Languages.Phrase AbsorbDamage = new Languages.Phrase("affect.absorb.damage");
        public static readonly Languages.Phrase AbsorbHeal = new Languages.Phrase("affect.absorb.heal");

        public readonly DamageType DmgType;
        public readonly bool Damage, Heal;

        public static Absorb Full(DamageType type) {
            return new Absorb(type, true, true);
        }
        public static Absorb OnlyDamage(DamageType type) {
            return new Absorb(type, false, true);
        }
        public static Absorb OnlyHeal(DamageType type) {
            return new Absorb(type, true, true);
        }

        private Absorb(DamageType type, bool damage, bool heal) {
            DmgType = type;
            Damage = damage;
            Heal = heal;
        }

        public override string Id {
            get { return "absorb"; }
        }
        public override Languages.Phrase Name {
            get {
                if (Damage)
                    return Heal ? AbsorbFull : AbsorbFull;
                else
                    return Heal ? AbsorbHeal : null;
            }
        }
        public override string NameText {
            get { return Name != null ? Name.GetText(DmgType.AffectName) : string.Empty; }
        }

        public override int BaseWeight {
            get { return Damage ? (Heal ? 10 : 30) : -20; }
        }

        public override Affect Clone() {
            return new Absorb(DmgType, Damage, Heal);
        }

        public override void SetAffect() {
            base.SetAffect();
            if (Damage) LocalSummary.DamageAbsorbs.Add(this);
            if (Heal) LocalSummary.HealAbsorbs.Add(this);
        }
        public override void ResetAffect() {
            base.ResetAffect();
            if (Damage) LocalSummary.DamageAbsorbs.Remove(this);
            if (Heal) LocalSummary.HealAbsorbs.Remove(this);
        }

        public static DamageType Getter(Absorb affect) {
            return affect.DmgType;
        }
    }
}